/*
  Copyright 2011 fullkawa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package jp.fullkawa.xnovel.content;

import jp.fullkawa.xnovel.Scene;
import jp.fullkawa.xnovel.exception.RequireException;

/**
 * 条件分岐
 * @author fullkawa
 */
public class Branch extends Content
{
	/**
	 * 条件式
	 */
	private String condition;

	/**
	 * 条件式がtrueのときの移動先
	 */
	private Scene linkTo;

	public Branch() {}

	public Branch(String condition, Scene linkTo)
	{
		this();
		this.setCondition(condition);
		this.setLinkTo(linkTo);
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public Scene getLinkTo() {
		return linkTo;
	}

	public void setLinkTo(Scene linkTo) {
		this.linkTo = linkTo;
	}

	@Override
	public String getTag()
	{
		Scene link = this.getLinkTo();
		if (link == null)
		{
			throw new RequireException("分岐先のシーンが設定されていません。");
		}

		String link_id = link.getId();
		if (link_id == null || link_id.length() == 0)
		{
			throw new RequireException("分岐先シーンのIDが設定されていません。");
		}

		String cond = this.getCondition();
		if (cond == null || cond.length() == 0)
		{
			throw new RequireException("条件式が記述されていません。");
		}

		Object[] o = { link_id, cond };
		return super.getTag("tag.branch", o);
	}
}
